import "package:ct_pa_majordomo/config/roomIcons.dart";
import "package:ct_pa_majordomo/config/theme_vars.dart";
import "package:ct_pa_majordomo/pages/device/entrance_guard/face/index.dart";
import "package:ct_pa_majordomo/pages/device/entrance_guard/setting/index.dart";
import "package:ct_pa_majordomo/pages/device/entrance_guard/widgets/operation_record/index.dart";
import "package:ct_pa_majordomo/router/keys.dart";
import "package:ct_pa_majordomo/utils/stacker.dart";
import "package:ct_pa_majordomo/widgets/wrap_item.dart";
import "package:flutter/cupertino.dart";
import "package:flutter/material.dart";

class Config {
  final String name;
  final String path;
  final Object? arguments;
  final Icon icon;
  Config(this.name, this.path, this.arguments, this.icon);
}

class Operation extends StatefulWidget {
  final Map? info;
  const Operation({super.key, this.info});

  @override
  State<StatefulWidget> createState() => _OperationState();

}

class _OperationState extends State<Operation> {

  List<Config> _config = [];

  @override
  void initState() {
    // setState(() {
    //   print("info:>>>> ${widget.info}");
    //   _config = [
    //     Config("人脸", Face(info: widget.info)),
    //     // Config("密码", PasswordKey()),
    //     // Config("IC卡", null),
    //     Config("操作记录", OperationRecord()),
    //     Config("设置", Setting())
    //   ];
    // });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    _config = [
      Config("人脸", Keys.DEVICE_ENTRANCEGUARD_FACE, widget.info, const Icon(RoomIcons.operation_record)),
      // Config("操作记录", Keys.DEVICE_ENTRANCEGUARD_OPERATION, null,  const Icon(RoomIcons.operation_record)),
      Config("设置", Keys.DEVICE_ENTRANCEGUARD_SETTING, widget.info,  const Icon(RoomIcons.setting)),
    ];
    return DecoratedBox(
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(12),
          boxShadow: const [ThemeVars.boxShadow],
          color: Colors.white,
        ),
        child: Container(
          padding: const EdgeInsets.symmetric(vertical: 16),
          child: Wrap(
            children: _config.map((ele) {
              return GestureDetector(
                behavior: HitTestBehavior.opaque,
                onTap: () {
                  Stacker.pushNamed(ele.path, arguments: ele?.arguments);
                  // if (ele.pages != null) {
                  //   Navigator.push(
                  //       context,
                  //       CupertinoPageRoute(builder: (BuildContext context) {
                  //         return ele.pages!;
                  //       })
                  //   );
                  // }
                },
                child: WrapItem(
                    span: 4,
                    child: Container(
                      padding: const EdgeInsets.symmetric(vertical: 16),
                      child: Center(
                        child: Column(
                          children: [
                            SizedBox(
                              width: 40,
                              height: 40,
                              child: ele.icon,
                            ),
                            const SizedBox(height: 10,),
                            Text(ele.name, style: const TextStyle(fontWeight: FontWeight.w600),),
                          ],
                        ),
                      ),
                    )
                ),
              );
            }).toList(),
          ),
        )
    );
  }

}